package com.example.design.iterator.test1;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 升级版服务员，通过迭代器，服务员能用同一个接口返回不同类型的菜单，能够随意增加菜单
 */
public class WaitressLeve2 {
    ArrayList menus;
    public WaitressLeve2(ArrayList menus){
        this.menus = menus;
    }

    public void printMenu(){
        Iterator menusIterator = menus.iterator();
        while (menusIterator.hasNext()) {
            Menu menu = (Menu)menusIterator.next();
            //System.out.println("打印" + menu. + "龙菜单。。。。。。");
            printMenu(menu.createIterator());
            System.out.println();
        }
    }

    private void printMenu(Iterator iterator){
        while (iterator.hasNext()){
            MenuItem item = (MenuItem)iterator.next();
            System.out.println("名称：" +item.getName()
                    +",单价：" + item.getPrice() + "，菜单说明：" + item.getDescription());
        }
    }
}
